(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

and(tt, X) → activate(X)
plus(N, 0) → N
plus(N, s(M)) → s(plus(N, M))
x(N, 0) → 0
x(N, s(M)) → plus(x(N, M), N)
activate(X) → X

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

and(tt, X) → activate(X) [1]
plus(N, 0) → N [1]
plus(N, s(M)) → s(plus(N, M)) [1]
x(N, 0) → 0 [1]
x(N, s(M)) → plus(x(N, M), N) [1]
activate(X) → X [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

and(tt, X) → activate(X) [1]
plus(N, 0) → N [1]
plus(N, s(M)) → s(plus(N, M)) [1]
x(N, 0) → 0 [1]
x(N, s(M)) → plus(x(N, M), N) [1]
activate(X) → X [1]

The TRS has the following type information:
and :: tt → and:activate → and:activate
tt :: tt
activate :: and:activate → and:activate
plus :: 0:s → 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
x :: 0:s → 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants:

const

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

and(tt, X) → activate(X) [1]
plus(N, 0) → N [1]
plus(N, s(M)) → s(plus(N, M)) [1]
x(N, 0) → 0 [1]
x(N, s(M)) → plus(x(N, M), N) [1]
activate(X) → X [1]

The TRS has the following type information:
and :: tt → and:activate → and:activate
tt :: tt
activate :: and:activate → and:activate
plus :: 0:s → 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
x :: 0:s → 0:s → 0:s
const :: and:activate

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

tt => 0
0 => 0
const => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

activate(z) -{ 1 }→ X :|: X >= 0, z = X
and(z, z') -{ 1 }→ activate(X) :|: z' = X, X >= 0, z = 0
plus(z, z') -{ 1 }→ N :|: z = N, z' = 0, N >= 0
plus(z, z') -{ 1 }→ 1 + plus(N, M) :|: z' = 1 + M, z = N, M >= 0, N >= 0
x(z, z') -{ 1 }→ plus(x(N, M), N) :|: z' = 1 + M, z = N, M >= 0, N >= 0
x(z, z') -{ 1 }→ 0 :|: z = N, z' = 0, N >= 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1),0,[and(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1),0,[plus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1),0,[x(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1),0,[activate(V, Out)],[V >= 0]).
eq(and(V, V1, Out),1,[activate(X1, Ret)],[Out = Ret,V1 = X1,X1 >= 0,V = 0]).
eq(plus(V, V1, Out),1,[],[Out = N1,V = N1,V1 = 0,N1 >= 0]).
eq(plus(V, V1, Out),1,[plus(N2, M1, Ret1)],[Out = 1 + Ret1,V1 = 1 + M1,V = N2,M1 >= 0,N2 >= 0]).
eq(x(V, V1, Out),1,[],[Out = 0,V = N3,V1 = 0,N3 >= 0]).
eq(x(V, V1, Out),1,[x(N4, M2, Ret0),plus(Ret0, N4, Ret2)],[Out = Ret2,V1 = 1 + M2,V = N4,M2 >= 0,N4 >= 0]).
eq(activate(V, Out),1,[],[Out = X2,X2 >= 0,V = X2]).
input_output_vars(and(V,V1,Out),[V,V1],[Out]).
input_output_vars(plus(V,V1,Out),[V,V1],[Out]).
input_output_vars(x(V,V1,Out),[V,V1],[Out]).
input_output_vars(activate(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. non_recursive : [activate/2]
1. non_recursive : [and/3]
2. recursive : [plus/3]
3. recursive [non_tail] : [x/3]
4. non_recursive : [start/2]

#### Obtained direct recursion through partial evaluation
0. SCC is completely evaluated into other SCCs
1. SCC is completely evaluated into other SCCs
2. SCC is partially evaluated into plus/3
3. SCC is partially evaluated into x/3
4. SCC is partially evaluated into start/2

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations plus/3
* CE 7 is refined into CE [10]
* CE 6 is refined into CE [11]


### Cost equations --> "Loop" of plus/3
* CEs [11] --> Loop 6
* CEs [10] --> Loop 7

### Ranking functions of CR plus(V,V1,Out)
* RF of phase [7]: [V1]

#### Partial ranking functions of CR plus(V,V1,Out)
* Partial RF of phase [7]:
- RF of loop [7:1]:
V1


### Specialization of cost equations x/3
* CE 9 is refined into CE [12,13]
* CE 8 is refined into CE [14]


### Cost equations --> "Loop" of x/3
* CEs [14] --> Loop 8
* CEs [13] --> Loop 9
* CEs [12] --> Loop 10

### Ranking functions of CR x(V,V1,Out)
* RF of phase [9]: [V1]
* RF of phase [10]: [V1]

#### Partial ranking functions of CR x(V,V1,Out)
* Partial RF of phase [9]:
- RF of loop [9:1]:
V1
* Partial RF of phase [10]:
- RF of loop [10:1]:
V1


### Specialization of cost equations start/2
* CE 2 is refined into CE [15]
* CE 3 is refined into CE [16,17]
* CE 4 is refined into CE [18,19,20]
* CE 5 is refined into CE [21]


### Cost equations --> "Loop" of start/2
* CEs [16,19] --> Loop 11
* CEs [15,17,18,20,21] --> Loop 12

### Ranking functions of CR start(V,V1)

#### Partial ranking functions of CR start(V,V1)


Computing Bounds
=====================================

#### Cost of chains of plus(V,V1,Out):
* Chain [[7],6]: 1*it(7)+1
Such that:it(7) =< V1

with precondition: [V+V1=Out,V>=0,V1>=1]

* Chain [6]: 1
with precondition: [V1=0,V=Out,V>=0]


#### Cost of chains of x(V,V1,Out):
* Chain [[10],8]: 2*it(10)+1
Such that:it(10) =< V1

with precondition: [V=0,Out=0,V1>=1]

* Chain [[9],8]: 2*it(9)+1*s(3)+1
Such that:aux(1) =< V
it(9) =< V1
s(3) =< it(9)*aux(1)

with precondition: [V>=1,V1>=1,Out+1>=V+V1]

* Chain [8]: 1
with precondition: [V1=0,Out=0,V>=0]


#### Cost of chains of start(V,V1):
* Chain [12]: 5*s(4)+1*s(8)+2
Such that:s(6) =< V
aux(2) =< V1
s(4) =< aux(2)
s(8) =< s(4)*s(6)

with precondition: [V>=0]

* Chain [11]: 1
with precondition: [V1=0,V>=0]


Closed-form bounds of start(V,V1):
-------------------------------------
* Chain [12] with precondition: [V>=0]
- Upper bound: nat(V1)*V+2+nat(V1)*5
- Complexity: n^2
* Chain [11] with precondition: [V1=0,V>=0]
- Upper bound: 1
- Complexity: constant

### Maximum cost of start(V,V1): nat(V1)*V+1+nat(V1)*5+1
Asymptotic class: n^2
* Total analysis performed in 134 ms.

(10) BOUNDS(1, n^2)